'use strict';
app.service('accountService',['$http','$q','utilService','$cookies',function($http,$q,utilService,$cookies){
    this.findBySessionId = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'system/user/find',
            params:{sessionId:$cookies.sessionId}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    this.updateNowSystemUser = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'system/user/now/'+ $scope.data.id,
            data:$scope.data,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.checkPhone = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'system/user/check/mobilePhone',
            params:{mobilePhone:$scope.systemUser.mobilePhone}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    this.getMobilePhoneCode = function($scope,mobilePhone){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'system/user/getMobilePhoneCode',
            params:{mobilePhone:mobilePhone}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

}]);